package com.ymatou.iapi.dguser.testcase;

import com.google.gson.JsonObject;
import com.ymatou.iapi.dguser.parameter.GetuserBean;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.dguser.parameter.UserDto;
import com.ymatou.iapi.dguser.service.GetuserCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P2;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.database.model.DGUserInfo;
import com.ymttest.database.sqlwapper.DGUserWapper;
import org.junit.*;
import org.junit.experimental.categories.Category;
/**
*根据UserId获取用户信息
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_Getuser{
	private static GetuserBean getuserBean;
	private static GetuserCall getuserCall;
	DGUserWapper DGUserWapper;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据UserId获取用户信息");
	}

	@Before
	public void caseUp() {
		getuserBean=new GetuserBean();
		getuserCall=new GetuserCall();
		DGUserWapper=new DGUserWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getuserCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	private void verifyDB(int userId) {
		DGUserInfo dgUserInfo = DGUserWapper.selectDGUserInfo(userId).get(0);
//		UserDto jet = getuserCall.getJsonObject().get("userDto").getAsJsonObject();
		UserDto jet=getuserCall.getUserDto();
		if (jet.getMobile() != null&&jet.getMobile().length()>1){
			Logger.verifyEquals(jet.getMobile(),dgUserInfo.getMobile(),"验证mobile");
		}
		if (jet.getMobileAreaCode() != null&&jet.getMobileAreaCode().length()>1){
			Logger.verifyEquals(jet.getMobileAreaCode() ,dgUserInfo.getMobileAreaCode(),"验证mobileAreaCode");
		}
		Logger.verifyEquals(jet.getNickname(),dgUserInfo.getNickname(),"验证nickname");
		if (dgUserInfo.getLogoUrl() == null||dgUserInfo.getLogoUrl().trim().length()<1){
			Logger.verifyEquals(jet.getLogoUrl(),DGUserCallService.DefImg,"验证logoUrl");
		}else {
			Logger.verifyEquals(jet.getLogoUrl(),dgUserInfo.getLogoUrl(),"验证logoUrl");
		}
		Logger.verifyEquals(jet.getGender(),dgUserInfo.getUserGender(),"验证gender");
		Logger.verifyEquals(jet.getUserType(),dgUserInfo.getUserType(),"验证userType");
		Logger.verifyEquals(jet.getUserStatus(),dgUserInfo.getUserStatus(),"验证userStatus");
		Logger.verifyEquals(jet.getCs(),dgUserInfo.getIsCs(),"验证getIsCs");
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Getuser_001() {
		Logger.start(true,"根据UserId获取用户信息");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			int user = DGUserCallService.UserCreateCall(u);
			getuserBean.setUserId(user);
			getuserCall.setData(getuserBean);
			getuserCall.callService();
			Logger.verifyEquals("true", getuserCall.getString("success"), "验证success");
			verifyDB(user);
		} catch (Exception e) {
			Logger.fail(e);
		}catch (Throwable throwable) {
			throwable.printStackTrace();
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_Getuser_002() {
		Logger.start(false,"不输入UserId失败");
		try {
//			UserCreateBean u = DGUserCallService.initUsercreateBean();
//			int user = DGUserCallService.UserCreateCall(u);
//			getuserBean.setUserId(user);
			getuserCall.setData(getuserBean);
			getuserCall.callService();
			Logger.verifyEquals("true", getuserCall.getString("success"), "验证success");
			boolean isnull=getuserCall.getJsonObject().has("userDto");
			Logger.verifyEquals(false,isnull,"验证没有userDto");
		} catch (Exception e) {
			Logger.fail(e);
		}catch (Throwable throwable) {
			throwable.printStackTrace();
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Getuser_003() {
		Logger.start(true,"根据UserId获取用户信息");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			u.setLogoUrl(null);
			int user = DGUserCallService.UserCreateCall(u);
			getuserBean.setUserId(user);
			getuserCall.setData(getuserBean);
			getuserCall.callService();
			Logger.verifyEquals("true", getuserCall.getString("success"), "验证success");
			verifyDB(user);
		} catch (Exception e) {
			Logger.fail(e);
		}catch (Throwable throwable) {
			throwable.printStackTrace();
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Getuser_004() {
		Logger.start(true,"根据UserId获取Seller用户信息");
		try {
			UserCreateBean u = DGUserCallService.initSellerUsercreateBean();
			int user = DGUserCallService.UserCreateCall(u);
			getuserBean.setUserId(user);
			getuserCall.setData(getuserBean);
			getuserCall.callService();
			Logger.verifyEquals("true", getuserCall.getString("success"), "验证success");
			verifyDB(user);
		} catch (Exception e) {
			Logger.fail(e);
		}catch (Throwable throwable) {
			throwable.printStackTrace();
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Getuser_005() {
		Logger.start(true,"增加了loginId返回值");
		try {
			UserCreateBean u = DGUserCallService.initSellerUsercreateBean();
			int user = DGUserCallService.UserCreateCall(u);
			getuserBean.setUserId(user);
			getuserCall.setData(getuserBean);
			getuserCall.callService();
			Logger.verifyEquals("true", getuserCall.getString("success"), "验证success");
			verifyDB(user);
			Logger.verifyNotEquals("", getuserCall.getJsonObject().getAsJsonObject("userDto").get("loginId").getAsString(), "验证不为空");
		} catch (Exception e) {
			Logger.fail(e);
		}catch (Throwable throwable) {
			throwable.printStackTrace();
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Getuser_006() {
		Logger.start(true,"根据UserId获取客服信息");
		try {
			UserCreateBean u = DGUserCallService.initCsUsercreateBean();
			int user = DGUserCallService.UserCreateCall(u);
			getuserBean.setUserId(user);
			getuserCall.setData(getuserBean);
			getuserCall.callService();
			Logger.verifyEquals("true", getuserCall.getString("success"), "验证success");
			verifyDB(user);
		} catch (Exception e) {
			Logger.fail(e);
		}catch (Throwable throwable) {
			throwable.printStackTrace();
		}
	}
}